package com.spotmanger.project.modular.spottable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spotmanger.project.common.core.utils.DataResult;
import com.spotmanger.project.modular.spottable.entity.SpottableZrzsEntity;
import com.spotmanger.project.modular.spottable.service.SpottableZrzsNewService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 自然灾损图斑的信息表。图斑类型为自然灾损图斑时填写该表。
 *
 * @author leihao
 * @email 1321451088@qq.com
 * @date 2021-09-20 10:53:23
 */
@Controller
@RequestMapping("/")
public class SpottableZrzsNewController {
    @Autowired
    private SpottableZrzsNewService spottableZrzsNewService;


    /**
     * 跳转到页面
     */
    @GetMapping("/index/spottableZrzsNew")
    public String spottableZrzsNew() {
        return "spottable/spottablezrzsNew/list";
    }

    @ApiOperation(value = "新增")
    @PostMapping("spottableZrzsNew/add")
    @RequiresPermissions("spottableZrzsNew:add")
    @ResponseBody
    public DataResult add(@RequestBody SpottableZrzsEntity spottableZrzsNew) {
        System.out.println(spottableZrzsNew.getTBBH());
        spottableZrzsNewService.save(spottableZrzsNew);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("spottableZrzsNew/delete")
    @RequiresPermissions("spottableZrzsNew:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        spottableZrzsNewService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("spottableZrzsNew/update")
    @RequiresPermissions("spottableZrzsNew:update")
    @ResponseBody
    public DataResult update(@RequestBody SpottableZrzsEntity spottableZrzsNew) {
        spottableZrzsNewService.updateById(spottableZrzsNew);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("spottableZrzsNew/listByPage")
    @RequiresPermissions("spottableZrzsNew:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SpottableZrzsEntity spottableZrzsNew) {
        Page page = new Page(spottableZrzsNew.getPage(), spottableZrzsNew.getLimit());
        //通过TBBH字段来实现模糊查询
        LambdaQueryWrapper<SpottableZrzsEntity> queryWrapper = spottableZrzsNewService.searchByTBBH(spottableZrzsNew);
        IPage<SpottableZrzsEntity> iPage = spottableZrzsNewService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
